package logic

import (
	"context"
	"errors"
	"order_srv/models"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateOrderStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateOrderStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderStatusLogic {
	return &UpdateOrderStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 订单状态修改
func (l *UpdateOrderStatusLogic) UpdateOrderStatus(in *order.UpdateOrderStatusRequest) (*order.UpdateOrderStatusResponse, error) {
	// todo: add your logic here and delete this line

	var o models.Order
	err := o.UpdateOrderStatus(in.OrderSn, int(in.Status))
	if err != nil {
		logx.Error("订单状态修改失败")
		return nil, errors.New("订单没状态修改失败")
	}

	return &order.UpdateOrderStatusResponse{}, nil
}
